home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / MPW IIGS Interfaces / AIIGSIncludes / M16.Util < prev    next >
Encoding:
Text File  |  1990-04-01  |  14.8 KB  |  619 lines  |  [TEXT/MPS ]

  1. *************************************************************************
  2. *                                                                        *
  3. *                        Apple //GS Utility Macros                        *
  4. *                                by                                        *
  5. *                            Lou Infeld                                    *
  6. *                                                                        *
  7. *                    Copyright Apple Computer, Inc. 1986-1988            *
  8. *                            All Rights Reserved                            *
  9. *                                                                        *
  10. *    Revision History                                                    *
  11. *    ----------------                                                    *
  12. *    v1.0R1 (04/29/87) --    First Release                                *
  13. *                            This file is a subset of the old            *
  14. *                                'M16.Utility'                            *
  15. *    v2.0R1 (01/22/88) --    First AsmIIGS release                        *
  16. *    v2.0R2 (02/11/88) --    "writelin" renamed "writeline"                *
  17. *    v2.0R3 (03/29/88) --    "|" added to pea instrs to avoid Assembler    *
  18. *                                warning                                    *
  19. *                            "pushlong" was incorrect if &offset was "s"    *
  20. *                                or not specified                        *
  21. *    v2.0R4 (04/14/88) --    "writestr" and "writeline" didn't restore    *
  22. *                            STRING setting                                *
  23. *    v2.0R5 (08/22/88) --    "inc4" and "dec4" redefined to support only    *
  24. *                                positive 4 byte integers                *
  25. *                            "sub4" fixed so that there will not be any    *
  26. *                                truncation warnings generated            *
  27. *                            Pull macros now check for missing parameter *
  28. *                                  or extra parameter                        *
  29. *    v2.0R6 (09/06/88) --    "dec4" fixed to support positive 4 byte        *
  30. *                                integers                                *
  31. *   v2.0R7 (4/4/89) -- changed "long" to "longmx", "short" to "shortmx" *
  32. *                      and added stack based macros (rls3)              *
  33. *************************************************************************
  34.  
  35. ;............................................................
  36. ;
  37. ;        Pull long (4 bytes) from stack
  38. ;
  39. ;    pulllong address             - pull off stack to address
  40. ;    pulllong addr1,addr2         - pull off stack into 2 places
  41. ;    pulllong [zeropage],offset   - pull off stack and store indirectly             
  42. ;    pulllong                     - pull off stack and leave in A
  43. ;...............................................................
  44.     MACRO
  45.     pulllong &addr1,&addr2
  46.     IF &addr1='' THEN
  47.     IF &addr2≠'' THEN 
  48.         AERROR 'Illegal 2nd parameter'
  49.     ENDIF
  50.         pullword
  51.         pullword
  52.     ELSEIF &addr2='' THEN
  53.         pullword  &addr1
  54.         pullword  &addr1+2
  55.     ELSEIF &addr1[1:1]='[' THEN
  56.         ldy   #&addr2
  57.         pullword  &addr1,y
  58.         ldy   #&addr2+2
  59.         pullword  &addr1,y
  60.     ELSE
  61.         pullword  &addr1
  62.         sta   &addr2
  63.         pullword  &addr1+2
  64.         sta   &addr2+2
  65.     ENDIF
  66.     MEND
  67. ;...............................................................
  68. ;
  69. ;        Pull 3 bytes from stack
  70. ;
  71. ;    pull3 addr    -- pulls bytes off stack and stores in 'loc'
  72. ;...............................................................
  73.     MACRO
  74.     pull3 &addr
  75.     IF &addr='' THEN
  76.         AERROR 'A parameter must be specified'
  77.     ENDIF
  78.         pull1    &addr
  79.         pullword  &addr+1
  80.     MEND
  81. ;...............................................................
  82. ;
  83. ;        Pull 2 bytes from stack
  84. ;
  85. ;    pullword loc     -- pulls bytes off stack and stores in 'loc'
  86. ;    pullword loc,x   -- pulls bytes off stack and stores in 'loc,x'
  87. ;    pullword         -- pulls bytes off stack and leaves in A
  88. ;...............................................................
  89.     MACRO
  90.     pullword &addr,®
  91.         pla
  92.     IF &addr≠'' THEN
  93.         IF ®≠'' THEN
  94.             sta        &addr,®
  95.         ELSE
  96.             sta        &addr
  97.         ENDIF
  98.     ELSEIF ®≠'' THEN 
  99.         AERROR 'Illegal 2nd parameter'
  100.     ENDIF
  101.     MEND
  102. ;...............................................................
  103. ;
  104. ;        Pull 1 byte from stack
  105. ;
  106. ;    pull1 loc     -- pulls byte off stack and stores in 'loc'
  107. ;    pull1 loc,x   -- pulls byte off stack and stores in 'loc,x'
  108. ;    pull1         -- pulls byte off stack and leaves in A
  109. ;...............................................................
  110.     MACRO
  111.     pull1 &addr,®
  112.         shortm
  113.         pullword    &addr,®
  114.         longm
  115.     MEND
  116. ;...............................................................
  117. ;
  118. ;        Push 1 byte onto stack
  119. ;
  120. ;    push1 loc     -- pushes byte onto stack from 'loc'
  121. ;    push1 loc,x   -- pushes byte onto stack from 'loc,x'
  122. ;    push1 #n      -- pushes constant #n onto stack
  123. ;    push1         -- pushes byte onto stack (from A)
  124. ;...............................................................
  125.     MACRO
  126.     push1 &addr,®
  127.         shortm
  128.         pushword &addr,®
  129.         longm
  130.     MEND
  131. ;............................................................
  132. ;
  133. ;        Push long (4 bytes) onto stack
  134. ;
  135. ;    pushlong address             - push contents of address
  136. ;    pushlong address,x           - push contents of address,x
  137. ;    pushlong const,s             - push contents of stack+const    
  138. ;    pushlong #address/const      - push address or constant
  139. ;    pushlong [zeropage],offset   - push using indirect address
  140. ;...............................................................
  141.     MACRO
  142.     pushlong &addr,&offset
  143.     IF &addr[1:1]='#' THEN
  144.         pea        &addr[2:255]>>16
  145.         pea        |&addr[2:255]
  146.     ELSEIF &addr[1:1]='[' THEN
  147.         ldy        #&offset+2
  148.         pushword &addr,y
  149.         ldy        #&offset
  150.         pushword &addr,y
  151.     ELSEIF &offset='s' THEN
  152.         pushword &addr+2,s
  153.         pushword &addr+2,s
  154.     ELSEIF &offset='' THEN
  155.         pushword  &addr+2
  156.         pushword  &addr
  157.     ELSE
  158.         pushword &addr+2,&offset
  159.         pushword &addr,&offset
  160.     ENDIF
  161.     MEND
  162. ;...............................................................
  163. ;
  164. ;        Push 3 bytes onto stack
  165. ;
  166. ;    push3 addr    -- pushes bytes onto stack from 'loc'
  167. ;    push3 addr,x  -- pushes bytes onto stack from 'loc,x'
  168. ;    push3 #n      -- pushes constant #n onto stack
  169. ;...............................................................
  170.     MACRO
  171.     push3 &addr,®
  172.     IF ®≠'' THEN
  173.         lda        &addr+1,®
  174.         pha
  175.         phb
  176.         lda        &addr,®
  177.         sta        1,s
  178.     ELSEIF &addr[1:1]='#' THEN
  179.         lda        #&addr[2:255]>>8
  180.         pha
  181.     GOTO .a
  182.     ELSE
  183.         lda        &addr+1
  184.         pha
  185. .a        phb
  186.         lda        &addr
  187.         sta        1,s
  188.     ENDIF
  189.     MEND
  190. ;...............................................................
  191. ;
  192. ;        Push 2 bytes onto stack
  193. ;
  194. ;    pushword loc     -- pushes bytes onto stack from 'loc'
  195. ;    pushword loc,x   -- pushes bytes onto stack from 'loc,x'
  196. ;    pushword #n      -- pushes constant #n onto stack
  197. ;    pushword         -- pushes bytes onto stack (from A)
  198. ;...............................................................
  199.     MACRO
  200.     pushword &addr,®
  201.     IF &addr[1:1]='#' AND &SETTING('LONGA')='ON' THEN
  202.         pea        |&addr[2:255]
  203.     ELSE
  204.         IF &addr≠'' THEN
  205.             IF ®≠'' THEN 
  206.                 lda        &addr,®
  207.             ELSE
  208.                 lda        &addr
  209.             ENDIF
  210.         ENDIF
  211.         pha
  212.     ENDIF
  213.     MEND
  214. ;...............................................................
  215. ;
  216. ;        Add 2 byte integers
  217. ;
  218. ;    add loc1,loc2,loc3 - adds 'loc1' to 'loc2' and stores in 'loc3'
  219. ;    add loc1,loc2      - adds 'loc1' to 'loc2' and leaves in A
  220. ;    add ,loc2,loc3     - adds A with 'loc2' and stores in 'loc3' 
  221. ;
  222. ;        'loc1' and 'loc2' can be constants
  223. ;...............................................................
  224.          MACRO
  225.     add   &a1,&a2,&a3
  226.     IF &a1≠'' THEN
  227.         lda        &a1
  228.     ENDIF
  229.         clc
  230.         adc        &a2
  231.     IF &a3≠'' THEN
  232.         sta        &a3
  233.     ENDIF
  234.     MEND
  235. ;...............................................................
  236. ;
  237. ;        Add 4 byte integers
  238. ;
  239. ;    add4 loc1,loc2,loc3 - adds 'loc1' to 'loc2' and stores in 'loc3'
  240. ;    add4 ,loc2,loc3     - adds A to 'loc2' and stores in 'loc3'
  241. ;
  242. ;        'loc1' and 'loc2' can be constants
  243. ;...............................................................
  244.     MACRO
  245.     add4    &a1,&a2,&a3
  246.     IF &a1≠'' THEN
  247.         lda        &a1
  248.     ENDIF
  249.         clc
  250.         adc        &a2
  251.         sta        &a3
  252.     IF &a1='' THEN
  253.         lda        #0
  254.     ELSEIF &a1[1:1]='#' THEN
  255.         lda        #^&a1[2:255]
  256.     ELSE
  257.         lda        &a1+2
  258.     ENDIF
  259.     IF &a2[1:1]='#' THEN
  260.         adc        #^&a2[2:255]
  261.     ELSE
  262.         adc        &a2+2
  263.     ENDIF
  264.         sta        &a3+2
  265.     MEND
  266. ;...............................................................
  267. ;
  268. ;        Increment a positive 4 byte integer
  269. ;
  270. ;    inc4 loc - increments 'loc'
  271. ;...............................................................
  272.     MACRO
  273.     inc4  &a1
  274.         inc        &a1
  275.         bne        @a
  276.         inc        &a1+2
  277. @a 
  278.     MEND
  279. ;...............................................................
  280. ;
  281. ;        Subtract 2 byte integers
  282. ;
  283. ;    sub loc1,loc2,loc3 - subtracts 'loc2' from 'loc1' and stores in 'loc3'
  284. ;    sub loc1,loc2      - subtracts 'loc2' from 'loc1' and leaves in A
  285. ;    sub ,loc2,loc3      - subtracts 'loc2' from A and stores in 'loc3' 
  286. ;
  287. ;        'loc1' and 'loc2' can be constants
  288. ;...............................................................
  289.     MACRO
  290.     sub   &a1,&a2,&a3
  291.     IF &a1≠'' THEN
  292.         lda        &a1
  293.     ENDIF
  294.         sec
  295.         sbc        &a2
  296.     IF &a3≠'' THEN
  297.         sta        &a3
  298.     ENDIF
  299.     MEND
  300. ;...............................................................
  301. ;
  302. ;        Subtract 4 byte integers
  303. ;
  304. ;    sub4 loc1,loc2,loc3 - subtracts 'loc2' from 'loc1' and stores in 'loc3'
  305. ;    sub4 ,loc2,loc3     - subtracts 'loc2' from A and stores in 'loc3'
  306. ;...............................................................
  307.     MACRO
  308.     sub4    &a1,&a2,&a3
  309.     IF &a1≠'' THEN
  310.     IF &a1[1:1]='#' THEN
  311.         lda        #<&a1[2:255]
  312.     ELSE
  313.         lda        &a1
  314.     ENDIF
  315.     ENDIF
  316.         sec
  317.     IF &a1[1:1]='#' THEN
  318.         sbc        #<&a2[2:255]
  319.     ELSE
  320.         sbc        &a2
  321.     ENDIF
  322.         sta        &a3
  323.     IF &a1='' THEN
  324.         lda        #0
  325.     ELSEIF &a1[1:1]='#' THEN
  326.         lda        #^&a1[2:255]
  327.     ELSE
  328.         lda        &a1+2
  329.     ENDIF
  330.     IF &a2[1:1]='#' THEN
  331.         sbc        #^&a2[2:255]
  332.     ELSE
  333.         sbc        &a2+2
  334.     ENDIF
  335.         sta        &a3+2
  336.     MEND
  337. ;...............................................................
  338. ;
  339. ;        Decrement a positive 4 byte integer
  340. ;
  341. ;    dec4 loc - decrements 'loc'
  342. ;...............................................................
  343.     MACRO
  344.     dec4  &a1
  345.         pha
  346.         sec
  347.         lda        &a1
  348.         sbc        #1
  349.         bcs        @a
  350.         dec        &a1+2
  351. @a         sta        &a1
  352.         pla
  353.     MEND
  354. ;...............................................................
  355. ;
  356. ;        Define string
  357. ;
  358. ;        Generates a Pascal type of string
  359. ;...............................................................
  360.     MACRO
  361.     str    &string
  362.         lclc    &sset
  363. &sset    SETC &SETTING('STRING')
  364.         STRING PASCAL
  365.         dc.B &string
  366.         STRING &sset
  367.     MEND
  368. ;...............................................................
  369. ;
  370. ;        Define pointer
  371. ;...............................................................
  372.     MACRO
  373.     dp    &pointer
  374.     dc.L &pointer
  375.     MEND
  376. ;...............................................................
  377. ;
  378. ;        Left Shift 4 bytes
  379. ;
  380. ;        asl4  loc,#n                   ;n is shift count (pos)
  381. ;        asl4  loc,lnum                 ;lnum contains shift count (pos)
  382. ;        asl4  loc                      ;X contains shift count (pos)
  383. ;...............................................................
  384.     MACRO
  385.     asl4 &loc,&num
  386.         lda   &loc+2
  387.     IF &num≠'' THEN
  388.         ldx   &num
  389.     ENDIF
  390. @a        asl        a
  391.         asl        &loc
  392.         adc        #0
  393.         dex
  394.         bne        @a
  395.         sta        &loc+2
  396.     MEND
  397. ;...............................................................
  398. ;
  399. ;        Right Shift 4 bytes
  400. ;
  401. ;        lsr4  loc,#n                   ;n is shift count (pos)
  402. ;        lsr4  loc,lnum                 ;lnum contains shift count (pos)
  403. ;        lsr4  loc                      ;X contains shift count (neg)
  404. ;...............................................................
  405.     MACRO
  406.     lsr4  &loc,&num
  407.     IF &num≠'' THEN
  408.         lda        &num
  409.         eor        #$FFFF
  410.         clc
  411.         adc        #1
  412.         tax
  413.     ENDIF
  414.         lda        &loc
  415. @a        lsr        a
  416.         lsr        &loc+2
  417.         bcc        @b
  418.         ora        #$8000
  419. @b        inx
  420.         bne        @a
  421.         sta        &loc
  422.     MEND
  423. ;...............................................................
  424. ;
  425. ;        Turn on native mode
  426. ;
  427. ;    The processor is put into 'native' mode.  8 bit or 16 bit
  428. ;    mode can be specified by using 'short' or 'long' as the
  429. ;    parameter.  If no parameter is specified, 'long' is assumed
  430. ;...............................................................
  431.     MACRO
  432.     native &mode
  433.         clc
  434.         xce
  435.     IF &mode≠'' THEN
  436.         &mode
  437.     ELSE
  438.         longmx
  439.     ENDIF
  440.     MEND
  441. ;...............................................................
  442. ;
  443. ;        Turn on emulation mode
  444. ;
  445. ;    The processor is put into 'emulation' mode.
  446. ;...............................................................
  447.     MACRO
  448.     emulation
  449.         sec
  450.         xce
  451.         longa    off
  452.         longi    off
  453.     MEND
  454. ;...............................................................
  455. ;
  456. ;        Set Memory & registers to 16 bits
  457. ;...............................................................
  458.     MACRO
  459.     longmx
  460.         rep        #%00110000
  461.         longa    on
  462.         longi    on
  463.     MEND
  464. ;...............................................................
  465. ;
  466. ;        Set Memory & A register to 16 bits
  467. ;...............................................................
  468.     MACRO
  469.     longm
  470.         rep        #%00100000
  471.         longa    on
  472.     MEND
  473. ;...............................................................
  474. ;
  475. ;        Set X & Y registers to 16 bits
  476. ;...............................................................
  477.     MACRO
  478.     longx
  479.         rep        #%00010000
  480.         longi    on
  481.     MEND
  482. ;...............................................................
  483. ;
  484. ;        Set Memory & registers to 8 bits
  485. ;...............................................................
  486.     MACRO
  487.     short
  488.         sep        #%00110000
  489.         longa    off
  490.         longi    off
  491.     MEND
  492. ;...............................................................
  493. ;
  494. ;        Set Memory & A register to 8 bits
  495. ;...............................................................
  496.     MACRO
  497.     shortm
  498.         sep        #%00100000
  499.         longa    off
  500.     MEND
  501. ;...............................................................
  502. ;
  503. ;        Set X & Y registers to 8 bits
  504. ;...............................................................
  505.     MACRO
  506.     shortx
  507.         sep        #%00010000
  508.         longi    off
  509.     MEND
  510. ;...............................................................
  511. ;
  512. ;        Write string
  513. ;
  514. ;        writestr loc     - string at loc 'loc'
  515. ;        writestr #'ABC'  - string='ABC'
  516. ;        writestr         - A,Y has loc of string         
  517. ;...............................................................
  518.     MACRO
  519.     writestr &addr
  520.     IF &addr≠'' THEN
  521.         IF &addr[1:1]='#' THEN
  522.             bra        @b
  523.             LCLC    &sset
  524. &sset        SETC    &SETTING('STRING')
  525.             STRING    PASCAL
  526. @a            DC.B    &addr[2:255]
  527.             STRING    &sset
  528. @b            pea        @a>>16
  529.             pea        |@a
  530.         ELSE
  531.             pea        &addr>>16
  532.             pea        |&addr
  533.         ENDIF
  534.     ELSE
  535.         phy
  536.         pha
  537.     ENDIF
  538.         ldx        #$1C0C
  539.         jsl        $E10000
  540.     MEND
  541. ;...............................................................
  542. ;
  543. ;        Write line (string+CR)
  544. ;
  545. ;        writeline loc     - string at loc 'loc'
  546. ;        writeline #'ABC'  - string='ABC'
  547. ;        writeline 'ABC'   - string='ABC'
  548. ;        writeline         - CR only
  549. ;
  550. ;...............................................................
  551.     MACRO
  552.     writeline &addr
  553.     IF &addr≠'' THEN
  554.         IF &addr[1:1]='#' OR &addr[1:1]='''' THEN
  555.             bra        @b
  556.             LCLC    &sset
  557. &sset        SETC    &SETTING('STRING')
  558.             STRING    PASCAL
  559.             IF &addr[1:1]='#' THEN
  560. @a                DC.B    &addr[2:255]
  561.             ELSE
  562. @a                DC.B    &addr[1:255]
  563.             ENDIF
  564.             STRING    &sset
  565. @b            pea        @a>>16
  566.             pea        |@a
  567.         ELSE
  568.             pea        &addr>>16
  569.             pea        |&addr
  570.         ENDIF
  571.     ELSE
  572.         pea        @c+1>>16
  573.         pea        |@c+1
  574.     ENDIF
  575.         ldx        #$1A0C
  576. @c        jsl        $E10000
  577.     MEND
  578. ;...............................................................
  579. ;
  580. ;        Write character
  581. ;
  582. ;        writech          - char in A register
  583. ;        writech #'A'     - char='A'
  584. ;        writech ch,x     - char in loc 'ch,x'
  585. ;...............................................................
  586.     MACRO
  587.     writech &addr,®
  588.     IF &addr≠'' THEN
  589.         IF ®≠'' THEN
  590.             lda        &addr,®
  591.         ELSE
  592.             lda        &addr
  593.         ENDIF
  594.     ENDIF
  595.         pha
  596.         ldx        #$180C
  597.         jsl        $E10000
  598.     MEND
  599. ;...............................................................
  600. ;
  601. ;              Read a char from keyboard
  602. ;
  603. ;        readch addr     - char stored in 'addr'
  604. ;        readch          - char left in A register
  605. ;
  606. ;...............................................................
  607.     MACRO
  608.     readch &addr
  609.         pea        0
  610.         pea        1
  611.         ldx        #$220C
  612.         jsl        $E10000
  613.         pla
  614.     IF &addr≠'' THEN
  615.         sta        &addr
  616.     ENDIF
  617.     MEND
  618.  
  619.